home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / QuickDraw GX / QuickDraw GX Info / QuickDraw GX Interfaces / Interfaces & Libraries / graphics libraries / oval library.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  2.2 KB  |  73 lines  |  [TEXT/MPS ]

  1. /* graphics libraries:
  2.     oval routines
  3.     by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  4.     Copyright 1987 - 1991 Apple Computer, Inc.  All rights reserved.    */
  5.  
  6.  
  7. #include "graphics libraries.h"
  8.  
  9. #define FRACROOT2less1  444758426
  10.  
  11. /*
  12.   * ovalPath must be 18 fixed numbers. Set the gxPath
  13.   * to the oval described in theOval.
  14.   */
  15. static void OvalPath(Fixed ovalPath[], const gxRectangle *r)
  16. {
  17.     register Fixed *pointWalker;
  18.     register Fixed cx, cy, h, v;
  19.  
  20.     cx = (r->left + r->right)/2;
  21.     cy = (r->top + r->bottom)/2;
  22.     h = FractMultiply(FRACROOT2less1, (r->right - r->left)/2);
  23.     v = FractMultiply(FRACROOT2less1, (r->bottom - r->top)/2);
  24.     pointWalker = ovalPath;                     /* start at the beginning       */
  25.     *pointWalker++ = 8;                         /* eight points             */
  26.     *pointWalker++ = 0xFF000000;                /* all points off gxCurve     */
  27. /*
  28.   * Start on the left edge, go up and around
  29.   */
  30.     *pointWalker++ = r->left;       *pointWalker++ = cy - v;
  31.     *pointWalker++ = cx - h;        *pointWalker++ = r->top;
  32.     *pointWalker++ = cx + h;        *pointWalker++ = r->top;
  33.     *pointWalker++ = r->right;  *pointWalker++ = cy - v;
  34.  
  35.     *pointWalker++ = r->right;  *pointWalker++ = cy + v;
  36.     *pointWalker++ = cx + h;        *pointWalker++ = r->bottom;
  37.     *pointWalker++ = cx - h;        *pointWalker++ = r->bottom;
  38.     *pointWalker++ = r->left;       *pointWalker++ = cy + v;
  39. }
  40.  
  41.  
  42. gxShape NewOval(const gxRectangle *ovalData)
  43. {
  44.     Fixed ovalPath[18];                              /* 1 vector count, 1 control bit long, 8 points */
  45.  
  46.     NilParamReturnNil(ovalData);
  47.     OvalPath(ovalPath, ovalData);
  48.     return NewPath((gxPath *) ovalPath);
  49. }
  50.  
  51. void SetOval(gxShape s, const gxRectangle *ovalData)
  52. {
  53.     Fixed ovalPath[18];
  54.  
  55.     NilShapeReturn(s);
  56.     NilParamReturn(ovalData);
  57.  
  58.     OvalPath(ovalPath, ovalData);
  59.     SetPath(s, 0, (gxPath *)ovalPath);
  60. }
  61.  
  62.  
  63. void DrawOval(const gxRectangle *ovalData, gxShapeFill geom)
  64. {
  65.     register gxShape ovalShape;
  66.     
  67.     NilParamReturn(ovalData);
  68.     ovalShape = NewOval(ovalData);
  69.     GXSetShapeFill(ovalShape, geom);
  70.     GXDrawShape(ovalShape);
  71.     GXDisposeShape(ovalShape);
  72. }
  73.